#syntax=docker/dockerfile:1.3-labs
ARG IMAGE_REPO=docker.io/library
ARG CENTOS_VERSION=centos8.4.2105
FROM ${IMAGE_REPO}/centos:${CENTOS_VERSION}  as builder
WORKDIR /opt
COPY ./jdk-8u361-linux-x64.tar.gz /opt/

# http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
## 解压后路径 jdk1.8.0_361
RUN tar -zxvf jdk-8u361-linux-x64.tar.gz 
ENV TINI_VERSION v0.19.0
# tini util
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tini
RUN chmod +x /usr/bin/tini
#ADD https://dlcdn.apache.org/maven/maven-3/3.9.0/binaries/apache-maven-3.9.0-bin.tar.gz apache-maven-3.9.0-bin.tar.gz
COPY ./apache-maven-3.9.0-bin.tar.gz .
RUN tar -zxvf apache-maven-3.9.0-bin.tar.gz 
FROM ${IMAGE_REPO}/centos:${CENTOS_VERSION} 
COPY --from=builder /opt/jdk1.8.0_361 /opt/jdk1.8.0_361
COPY --from=builder /usr/bin/tini /usr/bin/tini
COPY --from=builder /opt/apache-maven-3.9.0 /opt/apache-maven-3.9.0

ENV JAVA_HOME=/opt/jdk1.8.0_361
ENV JRE_HOME=${JAVA_HOME}/jre
ENV CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
ENV MAVEN_HOME=/opt/apache-maven-3.9.0

ENV PATH=${MAVEN_HOME}/bin:${JAVA_HOME}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

RUN dnf install -y openssh-clients openssh-server && \
     rm -rf /run/nologin && \
     echo "ListenAddress ::" >> /etc/ssh/sshd_config   && \
     echo "ListenAddress 0.0.0.0" >> /etc/ssh/sshd_config && \
     echo "Port 22" >> /etc/ssh/sshd_config && \
     ssh-keygen -A && \
     rm -rf /root/.ssh && mkdir -p /root/.ssh  && \
     ssh-keygen -t rsa -N '' -f /root/.ssh/id_rsa -q  && \
     #修改ssh配置(ssh_config&&sshd_config)
     sed -i -e 's|^\s*PasswordAuthentication|\#   PasswordAuthentication|g'   \
        -e 's|^\s*StrictHostKeyChecking|\#   StrictHostKeyChecking|g' /etc/ssh/ssh_config && \
     echo -e '     PasswordAuthentication yes\n     StrictHostKeyChecking no' >> /etc/ssh/ssh_config && \     
     cp /root/.ssh/id_rsa.pub  /root/.ssh/authorized_keys 


# ENV would be invalid while connecting by ssh.
# So we add bash enviroments here
RUN cat >/root/.bashrc <<EOF
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
export JAVA_HOME=${JAVA_HOME}
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export MAVEN_HOME=/opt/apache-maven-3.9.0
export PATH=${MAVEN_HOME}/bin:${JAVA_HOME}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
EOF
